package la.iok.hzsvn.lewin.movie.shopmovie.controller;

import la.iok.hzsvn.lewin.movie.core.Token;
import la.iok.hzsvn.lewin.movie.core.shopmovie.param.CouponUseParam;
import la.iok.hzsvn.lewin.movie.core.shopmovie.param.CouponUseRecordListParam;
import la.iok.hzsvn.lewin.movie.core.shopmovie.vo.CouponUseRecordVo;
import la.iok.hzsvn.lewin.movie.shopmovie.service.CouponUseRecordService;
import la.iok.hzsvn.lewin.mybatis.model.PageParam;
import la.iok.hzsvn.lewin.mybatis.model.PageVo;
import la.iok.hzsvn.lewin.mybatis.model.SortParam;
import la.iok.hzsvn.share.response.OperatorResponse;
import la.iok.hzsvn.share.response.OperatorResponses;
import la.iok.hzsvn.share.response.SingleDataResponse;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("couponUseRecords")
public class CouponUseRecordController {
    private final CouponUseRecordService couponUseRecordService;

    public CouponUseRecordController(CouponUseRecordService couponUseRecordService) {
        this.couponUseRecordService = couponUseRecordService;
    }

    @PostMapping
    public OperatorResponse save(@RequestHeader Token token, @RequestBody CouponUseParam param){
        couponUseRecordService.save(token, param.getCarpoolId(), param.getCouponId());
        return OperatorResponses.success();
    }

    @PostMapping("/choice")
    public OperatorResponse choice(@RequestHeader Token token, @RequestBody CouponUseParam param){
        couponUseRecordService.choice(token, param.getCarpoolId(), param.getCouponId(),param.getplayerFeeId());
        return OperatorResponses.success();
    }

    @DeleteMapping("/deleteRecord/{id}")
    public OperatorResponse deleteCouponUseRecord(@RequestHeader Token token, @PathVariable Long id) {
        couponUseRecordService.deleteCouponUseRecord(token,id);
        return OperatorResponses.success();
    }

    @GetMapping
    public SingleDataResponse<PageVo<CouponUseRecordVo>> page(@RequestHeader Token token, PageParam pageParam,
                                                              SortParam sortParam, CouponUseRecordListParam listParam){
        return new SingleDataResponse<>(couponUseRecordService.page(token, pageParam, sortParam, listParam));
    }

    @GetMapping("/select")
    public SingleDataResponse<PageVo<CouponUseRecordVo>> getpage(@RequestHeader Token token, PageParam pageParam,
                                                              SortParam sortParam, CouponUseRecordListParam listParam){
        return new SingleDataResponse<>(couponUseRecordService.getpage(token, pageParam, sortParam, listParam));
    }

    @PutMapping("{id}")
    public OperatorResponse confirm(@RequestHeader Token token, @PathVariable Long id){
        couponUseRecordService.confirm(token, id);
        return OperatorResponses.success();
    }
}
